<template>
  <div class="detail">
    <el-card>
      <el-tabs v-model="activeName" >
        <el-tab-pane label="登录账户设置" name="first">
            <el-form :model="form" label-width="100px" class="myform">
                <el-form-item label="姓名" >
                    <el-input v-model="form.username"></el-input>
                </el-form-item>
                <el-form-item label="密码">
                    <el-input v-model="form.password" type="password"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="saveBaseInfo">更新</el-button>
                    <el-button @click="$router.push('/employees')">取消</el-button>
                </el-form-item>
            </el-form>
        </el-tab-pane>
        <el-tab-pane label="个人详情" name="second">
            <userInfo></userInfo>
        </el-tab-pane>
        <el-tab-pane label="岗位信息" name="third">
            <jobInfo></jobInfo>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import {getEmployees, saveBaseInfoApi} from '@/api/employees'
export default {
  name: 'detail',
  data() {
      return {
          activeName:'first',
          form:{
              username:'',
              password:''
          },
          id:this.$route.query.id
      }
  },
  components:{
      userInfo:()=>import('@/views/employees/components/user-info.vue'),
      jobInfo:()=>import('@/views/employees/components/job-info.vue')
  },
  methods:{
      //获取员工信息
     async getBaseInfo(){
         let res = await getEmployees(this.id)
         console.log(res);
         this.form = res.data
      },
      //保存员工信息
      async saveBaseInfo(){
          let res = await saveBaseInfoApi(this.form)
          console.log(res);
          this.$message.success('更新用户成功')
      }
  },
  created(){
      this.getBaseInfo()
  }
}
</script>

<style lang='scss'>
.detail{
    .myform{
        width: 400px;
        margin: 20px 250px;
    }
}
</style>
